package com.bw.unit3.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.bw.unit3.base.BaseBean
import com.bw.unit3.base.BaseViewModel
import com.bw.unit3.bean.BannerBean
import com.bw.unit3.bean.GoodsBean
import com.bw.unit3.bean.GoodsDetailBean
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
 *
 * @ClassName: HomeViewModel
 * @Description: java类作用描述
 * @Author: zhangyanchao
 * @CreateDate: 2024/9/19 4:49 PM
 * @Version: 1.0
 */
class GoodsDetailViewModel : BaseViewModel() {

    val liveDataGoods = MutableLiveData<BaseBean<GoodsDetailBean>>()
    val liveDataCart = MutableLiveData<BaseBean<String>>()


    fun getGoodsDeail(id: Int) {
        viewModelScope.launch(Dispatchers.IO) {
            liveDataGoods.postValue(apiService.getGoodsDetail(id))
        }

    }

    fun addCart(map: Map<String,String>){
        viewModelScope.launch(Dispatchers.IO) {
            liveDataCart.postValue(apiService.addCart(map))
        }
    }
}